<template>
    <Submenu v-if="menu.list && menu.list.length > 0" :name="menu.name">
        <template slot="title">
            <Icon :type="'ios-'+menu.icon" />
            {{menu.name}}
        </template>
        <sider-menu
            v-for="item in menu.list"
            :key="item.menuId"
            :menu="item"
            :dynamicMenuRoutes="dynamicMenuRoutes"
        ></sider-menu>
    </Submenu>
    <MenuItem
        v-else
        :index="menu.menuId + ''"
        :name="menu.name+'-'+menu.type"
        @click.native="gotoRouteHandle(menu)"
    >
        <Icon :type="'ios-'+menu.icon"></Icon>
        <span>{{menu.name}}</span>
    </MenuItem>
    <!-- <MenuItem name="1-3">
        <Icon type="ios-settings"></Icon>
        <span>Option 3</span>
    </MenuItem>-->
</template>

<script>
import SiderMenu from "./main-sider-menu";

export default {
    props: {
        menu: {
            type: Object,
            required: true
        },
        dynamicMenuRoutes: {
            type: Array,
            required: true
        }
    },
    name: "sider-menu",
    components: {
        SiderMenu
    },
    computed: {
        sidebarLayoutSkin: {
            get() {
                console.log(this.$store.state.common.sidebarLayoutSkin);
                return this.$store.state.common.sidebarLayoutSkin;
            }
        }
    },
    methods: {
        // 通过menuId与动态(菜单)路由进行匹配跳转至指定路由
        gotoRouteHandle(menu) {
            // console.log("dynamicMenuRoutes====>",this.dynamicMenuRoutes)
            var route = this.dynamicMenuRoutes.filter(
                item => item.meta.menuId === menu.menuId
            );
            if (route.length >= 1) {
                // console.log("route[0].name=====>",route[0].name)
                this.$router.push({ name: route[0].name });
            }
        }
    }
};
</script>